<template>
    <div>
      <h1>科室列表页面</h1>
      <a href="/AddClassView">科室信息添加</a>
      <br>
      <a href="/AddView">医生信息添加</a>
      <br>
      科室名称：<input type="text" v-model="find.name">
      创建时间：<input type="date" v-model="find.d1"> - <input type="date" v-model="find.d2">
      <input type="button" value="查询" @click="Show">
      <input type="button" value="重置" @click="Chong">
      <table class="tabl">
        <thead>
            <tr>
                <td>科室编号</td>
                <td>科室名称</td>
                <td>科室人数</td>
                <td>科室描述</td>
                <td>创建时间</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody v-for="a in data">
            <tr>
                <td>{{a.cid  }}</td>
                <td>{{ a.name }}</td>
                <td>{{a.program  }}</td>
                <td>{{a.miaoshu  }}</td>
                <td>{{moment(a.startTime).format("YYYY-MM-DD")  }}</td>
                <td><input type="button" value="逻辑删除" @click="DelClass(a.cid)">
                <input type="button" value="编辑" @click="UptClaa(a.cid)"></td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import moment from "moment";
import { useRouter } from "vue-router";
const router=useRouter()
const UptClaa=(val:any)=>{
    router.push({path:"/UptClassView",query:{id:val}})
}
    
const data=ref([{
"cid": 1,
    "name": "内科",
    "program": 10,
    "miaoshu": "专门攻克内科疾病的",
    "startTime": "2025-05-19T02:24:32.792",
    "isDelete": true
}])
onMounted(()=>{
    Show()
   
})
const Show=()=>{
    axios.get("https://localhost:7140/api/RoomClass/GetById",{params:find.value}).then(res=>{
        data.value=res.data
    })
}
const find=ref({
    name:"",
    d1:null,
    d2:null
})
const Chong=()=>{
    find.value.name="",
    find.value.d1=null,
    find.value.d2=null
}
const DelClass=(id:any)=>{
    if(!confirm("确认删除吗")){
        return;
    }
    axios.delete("https://localhost:7140/api/RoomClass/DelRoom",{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert('删除成功');
            Show();
        }
        else{
            alert('删除失败');
        }
    })
}
</script>

<style scoped>

</style>